<?php
$git_adindex_02 = git_get_option('git_adindex_02');
if ($git_adindex_02) echo '<div class="banner banner-sticky">'.$git_adindex_02.'</div>'; 
if (is_home()) { 
    if (git_get_option('hot_list_check') || git_get_option('git_sticky_b')) { ?>
		<div><div class="left-ad" style="clear: both;background-color: #fff; width: 30%;float: left;margin-right:2%;"></div><div class="hot-posts">
			<h2 class="title"><?php echo git_get_option('hot_list_title') ?></h2>
			<ul><?php hot_posts_list(); ?></ul>
		</div></div>
	<?php
    } 
} ?>
<style type="text/css">.widget-title{background:#FFFFFF;} .title-h2{ height: 45px; border-bottom: 1px solid #90BBA8; margin: 5px 20px;}</style>
<div class="relates"><h2 class="title"><small>最新文章</small></h2>
	<ul style="padding: 5px 0px 15px 20px;">
	    <?php
		$result = $wpdb->get_results("SELECT ID,post_title FROM $wpdb->posts where post_status='publish' and post_type='post' ORDER BY ID DESC LIMIT 0 , 10");
		foreach ($result as $post) {
			setup_postdata($post);
			$postid = $post->ID;
			$title = $post->post_title;
		?>
	    <li><i class="fa fa-minus"></i>
			<a class="lastitle" href="<?php echo get_permalink($postid); ?>" title="<?php echo $title; ?>"><?php echo $title; ?></a>
			<!--<span>[<?php //the_time('Y-m-d'); ?>]</span>-->
		</li>
	    <?php
	} ?>
	</ul>
</div>

<?php
$_author = git_get_option('git_post_author_b');
$_time = git_get_option('git_post_time_b');
$_views = git_get_option('git_post_views_b');
$_comment = git_get_option('git_post_comment_b');
$_like = git_get_option('git_post_like_b');

$catCount = 8;
$catNum = 0;
$showPostCount = git_get_option('git_cat_num')?git_get_option('git_cat_num'):4;
while(++$catNum <= $catCount) :
	$cat_id = git_get_option('git_cat_'.$catNum);
	if ($cat_id) {
		query_posts(array(
			'showposts' => $showPostCount,
			'cat' => $cat_id
		));
	    if(!have_posts()) continue; ?>
	    <div class="widget-title">
			<h2 class="title-h2"><small><?php
	    		echo get_cat_name($cat_id); ?></small><span class="more" style="float:right;"><a style="left: 0px;" href="<?php
	    		echo get_category_link($cat_id); ?>" title="阅读更多" target="_blank"><small>阅读更多</small></a></span></h2>
			<div class="related_posts">
			<?php
		    if(have_posts()) : the_post();
			    $_thumbnail = false;
			    if (has_post_thumbnail() || !git_get_option('git_thumbnail_b')) {
			        $_thumbnail = true;
			    }
				?>
	        	<article class="excerpt<?php
				    echo !$_thumbnail ? ' excerpt-nothumbnail' : '' ?>">
					<header><?php
				    if (!is_category()) {
				        $category = get_the_category();
				        if ($category[0]) {
				            echo '<a class="label label-important" href="' . get_category_link($category[0]->term_id) . '">' . $category[0]->cat_name . '<i class="label-arrow"></i></a>';
				        }
				    }; ?><h2><a target="_blank" href="<?php
				    the_permalink() ?>" title="<?php
				    the_title(); ?>"><?php
				    the_title(); ?>
				 <?php
				    $t1 = $post->post_date;
				    $t2 = date("Y-m-d H:i:s");
				    $diff = (strtotime($t2) - strtotime($t1)) / 3600;
				    if ($diff < 12) {
				        echo '<img src="' . get_bloginfo("template_url") . '/img/new.gif" alt="24小时内最新">';
				    } ?> </a></h2>
					</header>
				<?php
				    if ($_thumbnail) { ?>
				<div class="focus"><a target="_blank" href="<?php
				        the_permalink(); ?>">
				<?php
			        if (git_get_option('git_qncdnplugin_b') ||git_get_option('git_cdnurl_b')) {
			            echo '<img class="thumb" src="';
			            echo post_thumbnail_src();
			            echo '?imageView2/1/w/';
			            echo git_get_option('git_thumb_width') ? git_get_option('git_thumb_width') : 200;
			            echo '/h/';
			            echo git_get_option('git_thumb_height') ? git_get_option('git_thumb_height') : 130;
			            echo '/q/85" alt="' . get_the_title() . '" />';
			        } else {
			            echo '<img class="thumb" src="' . get_bloginfo("template_url") . '/timthumb.php?src=';
			            echo post_thumbnail_src();
			            echo '&h=';
			            echo git_get_option('git_thumb_height') ? git_get_option('git_thumb_height') : 130;
			            echo '&w=';
			            echo git_get_option('git_thumb_width') ? git_get_option('git_thumb_width') : 200;
			            echo '&q=90&zc=1&ct=1" alt="' . get_the_title() . '" />';
			        } ?>
				</a></div>
					<?php
				    } ?>
				<p class="auth-span">
					<?php
				    if (!is_author() && !$_author) { ?>
						<span class="muted"><i class="fa fa-user"></i> <a href="<?php
				        echo get_author_posts_url(get_the_author_meta('ID')) ?>"><?php
				        echo get_the_author() ?></a></span>
					<?php
				    } ?>
					<?php
				    if (!$_time) { ?><span class="muted"><i class="fa fa-clock-o"></i> <?php
				        echo timeago(get_gmt_from_date(get_the_time('Y-m-d G:i:s'))) ?></span><?php
				    } ?>
					<?php
				    if (!$_views) { ?><span class="muted"><i class="fa fa-eye"></i> <?php
				        deel_views('浏览'); ?></span><?php
				    } ?>
					<?php
				    if (!$_comment) { ?><span class="muted"><i class="fa fa-comments-o"></i> <?php
				        if (comments_open()) echo '<a target="_blank" href="' . get_comments_link() . '">' . get_comments_number('0', '1', '%') . '评论</a>'
				?></span><?php
				    } ?>
				<?php
				    if (!$_like) { ?><span class="muted">
					<a href="javascript:;" data-action="ding" data-id="<?php
				        the_ID(); ?>" id="Addlike" class="action<?php
				        if (isset($_COOKIE['bigfa_ding_' . $post->ID])) echo ' actived'; ?>"><i class="fa fa-heart-o"></i><span class="count"><?php
				        if (get_post_meta($post->ID, 'bigfa_ding', true)) {
				            echo get_post_meta($post->ID, 'bigfa_ding', true);
				        } else {
				            echo '0';
				        } ?></span>个赞</a></span><?php
				    } ?></p>
						<span class="note"> <?php
				    echo deel_strimwidth(strip_tags(apply_filters('the_content', strip_shortcodes($post->post_content))) , 0, git_get_option('git_excerpt_length') ? git_get_option('git_excerpt_length') : 180 , '……<a href="' . post_permalink() . '" rel="nofollow" class="more-link">继续阅读 &raquo;</a>'); ?></span>
				</article>
	        <?php endif;
	        if(have_posts()) : ?>
				<div class="relates">
					<ul>
			        	<?php while (have_posts()) : the_post(); ?>
						<li><i class="fa fa-minus"></i>
							<a href="<?php the_permalink() ?>"><?php the_title(); ?></a><span>[<?php the_time('Y-m-d'); ?>]</span>
					    </li>
		            	<?php endwhile; ?>
					</ul>
				</div>
            <?php endif; ?>
			</div>
		</div>
	<?php
	}
endwhile; ?>